package apps;

import java.io.File;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import model.exception.SVGException;
import view.AppFrame;
import controller.CloseListener;

public class Driver {

    public static void main(String[] args) {

	AppReg.getFrame(); // display main frame

	AppFrame frame = AppFrame.getSingletonInstance(); // get the window
							  // instance...
	frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // and set
								    // its
								    // default
								    // close
	frame.addWindowListener(new CloseListener()); // give it a window
						      // listener, for closing
						      // confirmation

	// Load file, static instance of the SVG class,
	// since we only really need one throughout the program

	try {

	    File f;

	    // Checking for arguments
	    if (args.length != 0) {
		f = new File(args[0]);

		if (f.exists() == true)
		    AppReg.getModel().LoadFile(f.getAbsolutePath());
		else
		    JOptionPane.showMessageDialog(AppReg.getFrame(),
			    "Command line file not found", "File not found",
			    JOptionPane.ERROR_MESSAGE);
	    }

	} catch (SVGException e) {
	    JOptionPane.showMessageDialog(AppReg.getFrame(), e.getMessage(),
		    "SVG Exception", JOptionPane.ERROR_MESSAGE);
	    System.out.println(e.getMessage());
	}
    }

}
